package com.chmingx.springcloud.controller;

import com.chmingx.springcloud.entities.CommonResult;
import com.chmingx.springcloud.entities.Payment;
import com.chmingx.springcloud.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    @PostMapping("/payment/create")
    public CommonResult<Integer> create(@RequestBody Payment payment) {
        System.out.println(payment);
        int result = paymentService.create(payment);
        if (result > 0) {
            return new CommonResult<>(200, "插入数据成功", result);
        } else {
            return new CommonResult<>(400, "插入数据失败", null);
        }
    }

    @GetMapping("/payment/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
        Payment payment = paymentService.getPaymentById(id);
        if (payment != null) {
            return new CommonResult<>(200, "获取数据成功", payment);
        } else {
            return new CommonResult<>(444, "没有对应记录id: " + id, null);
        }
    }
}
